<?php
namespace Libs\Common;

/*
 * Class calculate Zodiac & Constellation
 * @author ThamLT
 */
class ZodiacConstellationCommon
{
    /**
     * Convert birthday to masterdata constellation
     * @param string date yyyy/mm/dd or yyyy-mm-dd
     * @author ThamLT
     * */
    /**
     * Convert birthday to masterdata constellation
     * @param string date yyyy/mm/dd or yyyy-mm-dd
     * @author ThamLT
     * */
    public static function toConstellationCode($sBirthday){
        $strtotime = strtotime($sBirthday);
        $month = (int)date('m', $strtotime);
        $day = (int)date('d', $strtotime);
        $codeId = 0;
        if(($month == 3 && $day >20) || ($month == 4 && $day < 20)){
            $codeId = 1;
        }
        elseif(($month == 4 && $day >19) || ($month == 5 && $day < 21)){
            $codeId = 2;
        }
        elseif(($month == 5 && $day >20) || ($month == 6 && $day < 22)){
            $codeId = 3;
        }
        elseif(($month == 6 && $day >21) || ($month == 7 && $day < 23)){
            $codeId = 4;
        }
        elseif(($month == 7 && $day >22) || ($month == 8 && $day < 23)){
            $codeId = 5;
        }
        elseif(($month == 8 && $day >22) || ($month == 9 && $day < 23)){
            $codeId = 6;
        }
        elseif(($month == 9 && $day >22) || ($month == 10 && $day < 24)){
            $codeId = 7;
        }
        elseif(($month == 10 && $day >23) || ($month == 11 && $day < 23)){
            $codeId = 8;
        }
        elseif(($month == 11 && $day >22) || ($month == 12 && $day < 24)){
            $codeId = 9;
        }
        elseif(($month == 12 && $day >23) || ($month == 1 && $day < 20)){
            $codeId = 10;
        }
        elseif(($month == 1 && $day >19) || ($month == 2 && $day < 19)){
            $codeId = 11;
        }
        elseif(($month == 2 && $day >18) || ($month == 3 && $day < 21)){
            $codeId = 12;
        }

        return $codeId;
    }

    /**
     * Convert birthday to id of master zodiac
     * @param string date yyyy/mm/dd or yyyy-mm-dd
     * @author ThamLT
     * */
     public static function toZodiac($sBirthday)
     {
        $iYear = date('Y', strtotime($sBirthday));
        $codeId = 0;

        $aryZodiac = array(
                        array('name' => 'monkey', 'codeId' => 9),//than
                        array('name' => 'rooster', 'codeId' => 10),//dau
                        array('name' => 'dog', 'codeId' => 11),//tuat
                        array('name' => 'pig', 'codeId' => 12),//heo
                        array('name' => 'rat', 'codeId' => 1),//ty
                        array('name' => 'ox', 'codeId' => 2),//suu
                        array('name' => 'tiger', 'codeId' => 3),//dan
                        array('name' => 'rabbit', 'codeId' => 4),//mao
                        array('name' => 'dragon', 'codeId' => 5),//thin
                        array('name' => 'serpent', 'codeId' => 3),//ty (ran)
                        array('name' => 'horse', 'codeId' => 7),//ngo
                        array('name' => 'goat', 'codeId' => 8)//mui
                     );
        $modYear = $iYear % 12;

        if (!empty($aryZodiac[$modYear])) {
            $codeId = $aryZodiac[$modYear]['codeId'];
        }
        return $codeId;
     }
}
